from traits.api import HasTraits, Instance, on_trait_change
from traitsui.api import View, Group, Item
from mayavi.core.api import Engine
from traits.api import *
from traitsui.api import *
from mayavi.core.ui.api import MayaviScene, MlabSceneModel, SceneEditor
from numpy import sin, cos, mgrid, pi, sqrt

class Form(HasTraits):
    engine1 = Instance(Engine, args=())
    scene1 = Instance(MlabSceneModel)
    def _scene1_default(self):
        self.engine1.start()
        scene1 = MlabSceneModel(engine=self.engine1)
        return scene1

    engine2 = Instance(Engine, ())
    scene2 = Instance(MlabSceneModel)
    def _scene2_default(self):
        self.engine2.start()
        scene2 = MlabSceneModel(engine=self.engine2)
        return scene2

    @observe('scene1.activated')
    def populate_scene1(self,a):
        self.scene1.mlab.test_surf()

    @observe('scene2.activated')
    def populate_scene2(self,a):
        self.scene2.mlab.test_mesh()

    view = View(Group(Item('scene1',
                        editor=SceneEditor(scene_class=MayaviScene),
                        width=480, height=480)),
                Group(Item('scene2',
                        editor=SceneEditor(scene_class=MayaviScene),
                        width=480, height=480)),
                resizable=True)

from PyQt5.QtWidgets import *
class FormWidget(QWidget):
    def __init__(self):
        QWidget.__init__(self)
        layout = QHBoxLayout(self)
        layout.setContentsMargins(0, 0, 0, 0)
        layout.setSpacing(0)
        self.form = Form()
        layout.addWidget(self.form.edit_traits(parent=self, kind='subpanel').control)
formWidget = FormWidget()
if __name__ == '__main__':
    import os
    import sys

    app = QApplication(sys.argv)
    formWidget.show()
    sys.exit(app.exec_())

